/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/05/03
*/
#ifndef __EDUI_BASE_H__
#define __EDUI_BASE_H__

#include "../defines.h"

EDUI_NAMESPACE_BEGIN

class IWindow;

#define EDUI_MIN(a,b) ((a)<(b)?(a):(b))
#define EDUI_MAX(a,b) ((a)>(b)?(a):(b))

typedef int TimerID;
typedef Uint32 (*TimerCallback) (TimerID id, Uint32 interval, IWindow* wnd, void *data1, void *data2);

typedef struct TimerInfo
{
    IWindow* wnd;
    TimerID id;
    TimerCallback callback;
    void *data1;
    void *data2;
    TimerInfo();
    ~TimerInfo();
} TimerInfo;

typedef enum WindowFlags
{
    WINDOW_FULLSCREEN = 0x00000001,         /**< fullscreen window */
    WINDOW_OPENGL = 0x00000002,             /**< window usable with OpenGL context */
    WINDOW_SHOWN = 0x00000004,              /**< window is visible */
    WINDOW_HIDDEN = 0x00000008,             /**< window is not visible */
    WINDOW_BORDERLESS = 0x00000010,         /**< no window decoration */
    WINDOW_RESIZABLE = 0x00000020,          /**< window can be resized */
    WINDOW_MINIMIZED = 0x00000040,          /**< window is minimized */
    WINDOW_MAXIMIZED = 0x00000080,          /**< window is maximized */
    WINDOW_INPUT_GRABBED = 0x00000100,      /**< window has grabbed input focus */
    WINDOW_INPUT_FOCUS = 0x00000200,        /**< window has input focus */
    WINDOW_MOUSE_FOCUS = 0x00000400,        /**< window has mouse focus */
    WINDOW_FULLSCREEN_DESKTOP = ( WINDOW_FULLSCREEN | 0x00001000 ),
    WINDOW_FOREIGN = 0x00000800,            /**< window not created by SDL */
    WINDOW_ALLOW_HIGHDPI = 0x00002000,      /**< window should be created in high-DPI mode if supported */
    WINDOW_MOUSE_CAPTURE = 0x00004000,      /**< window has mouse captured (unrelated to INPUT_GRABBED) */
    WINDOW_ALWAYS_ON_TOP = 0x00008000,      /**< window should always be above others */
    WINDOW_SKIP_TASKBAR  = 0x00010000,      /**< window should not be added to the taskbar */
    WINDOW_UTILITY       = 0x00020000,      /**< window should be treated as a utility window */
    WINDOW_TOOLTIP       = 0x00040000,      /**< window should be treated as a tooltip */
    WINDOW_POPUP_MENU    = 0x00080000       /**< window should be treated as a popup menu */
} WindowFlags;

#define WINDOWPOS_UNDEFINED 0x1FFF0000
#define WINDOWPOS_CENTERED  0x2FFF0000

typedef enum
{
    SYSTEM_CURSOR_ARROW,     /**< Arrow */
    SYSTEM_CURSOR_IBEAM,     /**< I-beam */
    SYSTEM_CURSOR_WAIT,      /**< Wait */
    SYSTEM_CURSOR_CROSSHAIR, /**< Crosshair */
    SYSTEM_CURSOR_WAITARROW, /**< Small wait cursor (or Wait if not available) */
    SYSTEM_CURSOR_SIZENWSE,  /**< Double arrow pointing northwest and southeast */
    SYSTEM_CURSOR_SIZENESW,  /**< Double arrow pointing northeast and southwest */
    SYSTEM_CURSOR_SIZEWE,    /**< Double arrow pointing west and east */
    SYSTEM_CURSOR_SIZENS,    /**< Double arrow pointing north and south */
    SYSTEM_CURSOR_SIZEALL,   /**< Four pointed arrow pointing north, south, east, and west */
    SYSTEM_CURSOR_NO,        /**< Slashed circle or crossbones */
    SYSTEM_CURSOR_HAND,      /**< Hand */
    NUM_SYSTEM_CURSORS,
    SYSTEM_CURSOE_ERROR, // no cursor,error
} SystemCursor;

//arrow,ibeam,wait,crosshair,waitarrow,sizenwse,sizenesw,sizewe,sizens,sizeall,no,hand
SystemCursor GetSystemCursorID(const char* name);

typedef enum TextureAccess
{
    TEXTUREACCESS_STATIC,    /**< Changes rarely, not lockable */
    TEXTUREACCESS_STREAMING, /**< Changes frequently, lockable */
    TEXTUREACCESS_TARGET     /**< Texture can be used as a render target */
} TextureAccess;

typedef enum RendererFlags
{
    RENDERER_SOFTWARE = 0x00000001,         /**< The renderer is a software fallback */
    RENDERER_ACCELERATED = 0x00000002,      /**< The renderer uses hardware
                                                     acceleration */
    RENDERER_PRESENTVSYNC = 0x00000004,     /**< Present is synchronized
                                                     with the refresh rate */
    RENDERER_TARGETTEXTURE = 0x00000008     /**< The renderer supports
                                                     rendering to texture */
} RendererFlags;

typedef enum BlendMode
{
    BLENDMODE_NONE = 0x00000000,     /**< no blending
                                              dstRGBA = srcRGBA */
    BLENDMODE_BLEND = 0x00000001,    /**< alpha blending
                                              dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
                                              dstA = srcA + (dstA * (1-srcA)) */
    BLENDMODE_ADD = 0x00000002,      /**< additive blending
                                              dstRGB = (srcRGB * srcA) + dstRGB
                                              dstA = dstA */
    BLENDMODE_MOD = 0x00000004       /**< color modulate
                                              dstRGB = srcRGB * dstRGB
                                              dstA = dstA */
} BlendMode;

typedef enum WndFullScreen
{
    WND_FULLSCREEN_WINDOWED,
    WND_FULLSCREEN_REAL,
    WND_FULLSCREEN_DESKTOP
} WndFullScreen;

typedef enum FontHinting
{
	FONT_HINTING_NORMAL = 0,
	FONT_HINTING_LIGHT  = 1,
	FONT_HINTING_MONO   = 2,
	FONT_HINTING_NONE   = 3,
} FontHinting;

typedef enum FontStyle
{
	FONT_STYLE_NORMAL        = 0x00,
	FONT_STYLE_BOLD          = 0x01,
	FONT_STYLE_ITALIC        = 0x02,
	FONT_STYLE_UNDERLINE     = 0x04,
	FONT_STYLE_STRIKETHROUGH = 0x08,
} FontStyle;

//find control flags
typedef enum FindType
{
    FIND_ALL        = 0x00000000,
    FIND_NODISABLED = 0x00000001,
    FIND_NOVISIBLE  = 0x00000002,
} FindType;

//text align
typedef enum AlignType
{
    ALIGN_CENTER = 0,
    ALIGN_LEFT,
    ALIGN_LEFTTOP,
    ALIGN_TOP,
    ALIGN_RIGHTTOP,
    ALIGN_RIGHT,
    ALIGN_RIGHTBOTTOM,
    ALIGN_BOTTOM,
    ALIGN_LEFTBOTTOM,
} AlignType;

typedef enum ButtonState
{
    BUTTON_STATE_NORMAL = 0,
    BUTTON_STATE_HOT,
    BUTTON_STATE_PRESSED,
    BUTTON_STATE_DISABLED,
} ButtonState;

struct EDUI_API Point
{
	int x;
	int y;
	Point():x(0),y(0){}
	Point(int x,int y):x(x),y(y){}
	void Reset(int x, int y);
};

struct EDUI_API PointF
{
	float x;
	float y;
	PointF():x(0),y(0){}
	PointF(float x,float y):x(x),y(y){}
	void Reset(float x, float y);
};

struct EDUI_API Size
{
	int w;
	int h;
	Size():w(0),h(0){}
	Size(int w,int h):w(w),h(h){}
	void Reset(int w, int h);
};

struct EDUI_API Rect
{
	int x,y;
	int w,h;
	Rect():x(0),y(0),w(0),h(0){}
	Rect(int x,int y,int w,int h):x(x),y(y),w(w),h(h){}
	void Reset(int x,int y,int w,int h);
	bool IsInRect(int _x, int _y);
	bool IsInRect(Point pt);
	void Offset(int dx);//
	void Union(const Rect* rc);//交集
	bool IsUnion(const Rect* rc);
	void Intersect(const Rect* rc);//并集
    bool IsOK() const;
    void Clear();
};

struct EDUI_API Rect1
{
	int l,t,r,b;
	Rect1():l(0),t(0),r(0),b(0){}
	Rect1(int l,int t,int r,int b):l(l),t(t),r(r),b(b){}
	void Reset(int _l, int _t, int _r, int _b);
};

struct EDUI_API Color
{
	Uint8 r;
	Uint8 g;
	Uint8 b;
	Uint8 a;
	Color():r(0),g(0),b(0),a(0){}
	Color(Uint8 r,Uint8 g,Uint8 b,Uint8 a):r(r),g(g),b(b),a(a){}
	Color(Uint32 col);//argb
    void Reset(const Color* color);
	void Reset(Uint8 _r,Uint8 _g,Uint8 _b,Uint8 _a);
	void Reset(Uint32 col);//argb
	Uint32 Value() const;//argb
};

// "false"->false, "true"->true,other->default
EDUI_API bool ParserBool(const char* src, bool bDefault = false);

//if src is int,fill out,else fill with default. 
EDUI_API bool ParserInt(const char* src, int* out, int bDefault = 0);

//error fill point with x,y
EDUI_API Point ParserPoint(const char* src, int x = 0, int y = 0);

//error fill size with w,h
EDUI_API Size ParserSize(const char* src, int w = 0, int h = 0);

//error fill rect with x,y,w,h
EDUI_API Rect ParserRect(const char* src, int x = 0, int y = 0, int w = 0, int h = 0);

//error fill rect1 with x,y,w,h
EDUI_API Rect1 ParserRect1(const char* src, int l = 0, int t = 0, int r = 0, int b = 0);

//error fill color with argb
EDUI_API Color ParserColor(const char* src, Uint32 argb = 0);

EDUI_API AlignType ParserAlign(const char* src, AlignType align = ALIGN_CENTER);

EDUI_API WndFullScreen ParserWndFullScreen(const char* src, WndFullScreen type = WND_FULLSCREEN_DESKTOP);

// get the character number of utf8 string.
EDUI_API Uint32 UTF8_CharNumber(const char* str);

// get the index character's position and length in string.return false if out of range.
EDUI_API bool UTF8_QueryChar(const char* str, Uint32 index, Uint32* pos, Uint32* len);

EDUI_NAMESPACE_END

#endif